/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FindProductPanel.java
 *
 * Created on 11-06-2010, 10:16:01
 */
package gruppe1projekt.GUILayer.product;

import gruppe1projekt.ControllerLayer.ProductController;
import gruppe1projekt.GUILayer.BaseWindow;
import gruppe1projekt.GUILayer.SearchList;
import gruppe1projekt.ModelLayer.Product;
import javax.swing.JOptionPane;

/**
 *
 * @author Kristian Byrialsen
 */
public class editProductPanel extends BaseWindow
{

    SearchList<Product> list;
    ProductController ctr;

    /** Creates new form FindProductPanel */
    public editProductPanel()
    {
        initComponents();

        this.RequiresLogin = true;

        ctr = new ProductController();

        list = new SearchList(ctr.getProducts());
        insertPanel(pnlSearchBox, list);

//        this.add(list);
        lblEditCountError.setText("");
        lblEditPurchasePriceError.setText("");
        lblEditNameError.setText("");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        pnlSearchBox = new javax.swing.JPanel();
        ShowButton = new javax.swing.JButton();
        lblBarcode = new javax.swing.JLabel();
        lblBarcodeLabel = new javax.swing.JLabel();
        lblNameLabel = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();
        lblNameLabel1 = new javax.swing.JLabel();
        lblName1 = new javax.swing.JLabel();
        lblPurchasePrice = new javax.swing.JLabel();
        lblPurchasePriceLabel = new javax.swing.JLabel();
        lblDescription = new javax.swing.JLabel();
        lblDescriptionLabel = new javax.swing.JLabel();
        lblCountLabel = new javax.swing.JLabel();
        lblCount = new javax.swing.JLabel();
        chkDiscontinued = new javax.swing.JCheckBox();
        btnEdit = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        lblEditBarcodeLabel = new javax.swing.JLabel();
        lblEditBarcode = new javax.swing.JLabel();
        lblEditNameLabel = new javax.swing.JLabel();
        txtEditName = new javax.swing.JTextField();
        lblEditDescriptionLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtEditDescription = new javax.swing.JTextArea();
        lblEditPurchasePriceLabel = new javax.swing.JLabel();
        txtEditPurchasePrice = new javax.swing.JTextField();
        lblEditCountLabel = new javax.swing.JLabel();
        txtEditCount = new javax.swing.JTextField();
        chkEditDiscontinued = new javax.swing.JCheckBox();
        btnSave = new javax.swing.JButton();
        lblEditNameError = new javax.swing.JLabel();
        lblEditPurchasePriceError = new javax.swing.JLabel();
        lblEditCountError = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(618, 580));
        setMinimumSize(new java.awt.Dimension(618, 580));
        setPreferredSize(new java.awt.Dimension(618, 580));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Find produkt", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 1, 14))); // NOI18N
        jPanel1.setMaximumSize(null);
        jPanel1.setPreferredSize(new java.awt.Dimension(594, 285));

        pnlSearchBox.setMaximumSize(null);
        pnlSearchBox.setVerifyInputWhenFocusTarget(false);

        javax.swing.GroupLayout pnlSearchBoxLayout = new javax.swing.GroupLayout(pnlSearchBox);
        pnlSearchBox.setLayout(pnlSearchBoxLayout);
        pnlSearchBoxLayout.setHorizontalGroup(
            pnlSearchBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 229, Short.MAX_VALUE)
        );
        pnlSearchBoxLayout.setVerticalGroup(
            pnlSearchBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 236, Short.MAX_VALUE)
        );

        ShowButton.setText("Vis info");
        ShowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShowButtonActionPerformed(evt);
            }
        });

        lblBarcode.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblBarcode.setMaximumSize(new java.awt.Dimension(180, 20));
        lblBarcode.setMinimumSize(new java.awt.Dimension(180, 20));
        lblBarcode.setPreferredSize(new java.awt.Dimension(180, 20));

        lblBarcodeLabel.setText("Barcode:");

        lblNameLabel.setText("Navn:");

        lblName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblName.setMaximumSize(new java.awt.Dimension(180, 20));
        lblName.setMinimumSize(new java.awt.Dimension(180, 20));
        lblName.setPreferredSize(new java.awt.Dimension(180, 20));

        lblNameLabel1.setText("Navn:");

        lblName1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblName1.setMaximumSize(new java.awt.Dimension(180, 20));
        lblName1.setMinimumSize(new java.awt.Dimension(180, 20));
        lblName1.setPreferredSize(new java.awt.Dimension(180, 20));

        lblPurchasePrice.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblPurchasePrice.setMaximumSize(new java.awt.Dimension(180, 20));
        lblPurchasePrice.setMinimumSize(new java.awt.Dimension(180, 20));
        lblPurchasePrice.setPreferredSize(new java.awt.Dimension(180, 20));

        lblPurchasePriceLabel.setText("Købspris:");

        lblDescription.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblDescription.setMaximumSize(new java.awt.Dimension(180, 20));
        lblDescription.setMinimumSize(new java.awt.Dimension(180, 20));
        lblDescription.setPreferredSize(new java.awt.Dimension(180, 20));

        lblDescriptionLabel.setText("Beskrivelse:");

        lblCountLabel.setText("Antal:");

        lblCount.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblCount.setMaximumSize(new java.awt.Dimension(180, 20));
        lblCount.setMinimumSize(new java.awt.Dimension(180, 20));
        lblCount.setPreferredSize(new java.awt.Dimension(180, 20));

        chkDiscontinued.setText("Udgået");
        chkDiscontinued.setEnabled(false);

        btnEdit.setText("Rediger");
        btnEdit.setEnabled(false);
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnDelete.setText("Slet");
        btnDelete.setEnabled(false);
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(pnlSearchBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnEdit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelete)
                        .addGap(169, 169, 169))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(chkDiscontinued)
                            .addContainerGap())
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(ShowButton)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(lblNameLabel)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(lblName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                            .addComponent(lblBarcodeLabel)
                                            .addGap(18, 18, 18)
                                            .addComponent(lblBarcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lblDescriptionLabel)
                                                .addComponent(lblPurchasePriceLabel)
                                                .addComponent(lblCountLabel))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lblPurchasePrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lblDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lblCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addContainerGap(74, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(lblNameLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                                .addComponent(lblName1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(76, 76, 76))))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlSearchBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(ShowButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblBarcodeLabel))
                            .addComponent(lblBarcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblNameLabel)
                            .addComponent(lblName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(lblDescriptionLabel)
                                .addGap(12, 12, 12)
                                .addComponent(lblPurchasePriceLabel)
                                .addGap(12, 12, 12)
                                .addComponent(lblCountLabel))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblPurchasePrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chkDiscontinued)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnEdit)
                            .addComponent(btnDelete))))
                .addGap(123, 123, 123)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblNameLabel1)
                    .addComponent(lblName1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Rediger produkt", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 1, 14))); // NOI18N
        jPanel2.setMaximumSize(null);
        jPanel2.setPreferredSize(new java.awt.Dimension(594, 268));

        lblEditBarcodeLabel.setText("Barcode:");

        lblEditBarcode.setMaximumSize(new java.awt.Dimension(160, 20));
        lblEditBarcode.setMinimumSize(new java.awt.Dimension(160, 20));
        lblEditBarcode.setPreferredSize(new java.awt.Dimension(160, 20));

        lblEditNameLabel.setText("Navn:");

        lblEditDescriptionLabel.setText("Beskrivelse:");

        txtEditDescription.setColumns(20);
        txtEditDescription.setRows(5);
        jScrollPane1.setViewportView(txtEditDescription);

        lblEditPurchasePriceLabel.setText("Købspris:");

        lblEditCountLabel.setText("Antal:");

        chkEditDiscontinued.setText("Udgået");

        btnSave.setText("Gem");
        btnSave.setEnabled(false);
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        lblEditNameError.setForeground(new java.awt.Color(255, 0, 0));
        lblEditNameError.setText("jLabel1");

        lblEditPurchasePriceError.setForeground(new java.awt.Color(255, 0, 0));
        lblEditPurchasePriceError.setText("jLabel1");

        lblEditCountError.setForeground(new java.awt.Color(255, 0, 0));
        lblEditCountError.setText("jLabel1");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(lblEditBarcodeLabel)
                        .addGap(18, 18, 18)
                        .addComponent(lblEditBarcode, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnSave)
                            .addComponent(chkEditDiscontinued)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblEditPurchasePriceLabel)
                                    .addComponent(lblEditCountLabel)
                                    .addComponent(lblEditNameLabel))
                                .addGap(17, 17, 17)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtEditName, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                                    .addComponent(txtEditCount, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                                    .addComponent(txtEditPurchasePrice, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                                    .addComponent(lblEditNameError)
                                    .addComponent(lblEditPurchasePriceError)
                                    .addComponent(lblEditCountError))))))
                .addGap(18, 18, 18)
                .addComponent(lblEditDescriptionLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblEditBarcodeLabel)
                    .addComponent(lblEditBarcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblEditNameLabel)
                            .addComponent(txtEditName, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblEditDescriptionLabel))
                        .addGap(1, 1, 1)
                        .addComponent(lblEditNameError)
                        .addGap(3, 3, 3)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblEditPurchasePriceLabel)
                            .addComponent(txtEditPurchasePrice, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(3, 3, 3)
                        .addComponent(lblEditPurchasePriceError)
                        .addGap(1, 1, 1)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblEditCountLabel)
                            .addComponent(txtEditCount, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(4, 4, 4)
                        .addComponent(lblEditCountError)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chkEditDiscontinued)
                        .addGap(18, 18, 18)
                        .addComponent(btnSave)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void ShowButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_ShowButtonActionPerformed
    {//GEN-HEADEREND:event_ShowButtonActionPerformed
        Product product = list.GetSelectedItem();

        if (product != null)
        {
            btnEdit.setEnabled(true);
            btnDelete.setEnabled(true);

            lblBarcode.setText(product.getBarcode() + "");
            lblCount.setText(product.getCount() + "");
            lblDescription.setText(product.getDescription());
            lblName.setText(product.getName());
            lblPurchasePrice.setText(product.getPurchasePrice() + "");
            chkDiscontinued.setSelected(product.IsDiscontinued());
        } else
        {
            clearActionShow();
        }
}//GEN-LAST:event_ShowButtonActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnEditActionPerformed
    {//GEN-HEADEREND:event_btnEditActionPerformed
        btnSave.setEnabled(true);

        Product product = ctr.getProduct(Long.parseLong(lblBarcode.getText()));

        lblEditBarcode.setText(Long.valueOf(product.getBarcode()).toString());
        txtEditName.setText(product.getName());
        txtEditCount.setText(product.getCount() + "");
        txtEditDescription.setText(product.getDescription());
        txtEditPurchasePrice.setText(product.getPurchasePrice() + "");
        chkEditDiscontinued.setSelected(product.IsDiscontinued());

//        txtType.setText(item.getType());
//        txtDescription.setText(item.getDescription());
//        txtDayPrice.setText(Double.valueOf(item.getDayPrice()).toString());

        clearActionShow();
    }//GEN-LAST:event_btnEditActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnDeleteActionPerformed
    {//GEN-HEADEREND:event_btnDeleteActionPerformed
        int SelectedOption = JOptionPane.showConfirmDialog(this, "Er du sikker på du vil slette produktet?");

        if (SelectedOption == JOptionPane.OK_OPTION)
        {
            ctr.deleteProduct(Long.parseLong(lblBarcode.getText()));
            list.setItems(ctr.getProducts());

            clearActionShow();
            clearActionUpdate();

            JOptionPane.showMessageDialog(this, "Produktet er slettet.");
        }
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSaveActionPerformed
    {//GEN-HEADEREND:event_btnSaveActionPerformed
                int selectedOption = JOptionPane.showConfirmDialog(this, "Er du sikker på at du vil redigere produktet?");
        if (selectedOption == JOptionPane.OK_OPTION)
        {
            if (IsValid())
            {
                Product product = ctr.getProduct(Long.parseLong(lblEditBarcode.getText()));

                if (product != null)
                {
                    product.setName(txtEditName.getText());
                    product.setPurchasePrice(Integer.parseInt(txtEditPurchasePrice.getText()));
                    product.setDescription(txtEditDescription.getText());
                    product.setCount(Integer.parseInt(txtEditCount.getText()));
                    product.setIsDiscontinued(chkEditDiscontinued.isSelected());

                    clearActionShow();
                    clearActionUpdate();

                    JOptionPane.showMessageDialog(this, "Oplysningerne er gemt.");
                }
            } else
            {
                JOptionPane.showMessageDialog(this, "Nogle af informationerne er ikke blevet tastet korrekt ind.");

            }
        }
    }//GEN-LAST:event_btnSaveActionPerformed

    @Override
    public boolean IsValid()
    {
        if (txtEditName.getText().equals(""))
        {
            lblEditNameError.setText("Du skal skrive noget i denne teksboks.");
            return false;
        }

        if (txtEditCount.getText().equals(""))
        {
            lblEditCountError.setText("Du skal skrive noget i denne teksboks.");
            return false;
        }

        if (!isInteger(txtEditCount.getText()))
        {
            lblEditCountError.setText("Der må kun stå tal i dette felt.");
            return false;
        }

        if (txtEditCount.getText().equals(""))
        {
            lblEditCountError.setText("Du skal skrive noget i denne teksboks.");
            return false;
        }

        if (txtEditPurchasePrice.getText().equals(""))
        {
            lblEditPurchasePriceError.setText("Du skal skrive noget i denne teksboks.");
            return false;
        }

        if (!isInteger(txtEditPurchasePrice.getText()))
        {
            lblEditPurchasePriceError.setText("Der må kun stå tal i dette felt.");
            return false;
        }

        Product product = ctr.getProduct(Long.parseLong(lblEditBarcode.getText()));

        if (product == null)
        {
            JOptionPane.showMessageDialog(this, "Produktet du prøvede at rette findes ikke");
            return false;
        }

        return true;
    }

    private void clearActionShow()
    {
        lblBarcode.setText("");
        lblDescription.setText("");
        lblCount.setText("");
        lblName.setText("");
        lblPurchasePrice.setText("");
        btnEdit.setEnabled(false);
        btnDelete.setEnabled(false);
    }

    private void clearActionUpdate()
    {
        lblEditBarcode.setText("");
        txtEditCount.setText("");
        txtEditDescription.setText("");
        txtEditName.setText("");
        txtEditPurchasePrice.setText("");

        lblEditCountError.setText("");
        lblEditNameError.setText("");
        lblEditPurchasePriceError.setText("");
        
        btnSave.setEnabled(false);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ShowButton;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnSave;
    private javax.swing.JCheckBox chkDiscontinued;
    private javax.swing.JCheckBox chkEditDiscontinued;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblBarcode;
    private javax.swing.JLabel lblBarcodeLabel;
    private javax.swing.JLabel lblCount;
    private javax.swing.JLabel lblCountLabel;
    private javax.swing.JLabel lblDescription;
    private javax.swing.JLabel lblDescriptionLabel;
    private javax.swing.JLabel lblEditBarcode;
    private javax.swing.JLabel lblEditBarcodeLabel;
    private javax.swing.JLabel lblEditCountError;
    private javax.swing.JLabel lblEditCountLabel;
    private javax.swing.JLabel lblEditDescriptionLabel;
    private javax.swing.JLabel lblEditNameError;
    private javax.swing.JLabel lblEditNameLabel;
    private javax.swing.JLabel lblEditPurchasePriceError;
    private javax.swing.JLabel lblEditPurchasePriceLabel;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblName1;
    private javax.swing.JLabel lblNameLabel;
    private javax.swing.JLabel lblNameLabel1;
    private javax.swing.JLabel lblPurchasePrice;
    private javax.swing.JLabel lblPurchasePriceLabel;
    private javax.swing.JPanel pnlSearchBox;
    private javax.swing.JTextField txtEditCount;
    private javax.swing.JTextArea txtEditDescription;
    private javax.swing.JTextField txtEditName;
    private javax.swing.JTextField txtEditPurchasePrice;
    // End of variables declaration//GEN-END:variables
}
